package com.v1.video.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.v1.video.R;
import com.v1.video.domain.AlbumItem;

/**
 * 发起请愿适配器
 * 
 * @author wangfang
 * 
 */
public class StartPetitionAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater mLayoutInflater;
	private List<AlbumItem> mLstData;

	public StartPetitionAdapter(Context context) {
		this.mContext = context;
		this.mLayoutInflater = LayoutInflater.from(context);
		mLstData = new ArrayList<AlbumItem>();
	}

	public List<AlbumItem> getmLstData() {
		return mLstData;
	}

	public void setmLstData(List<AlbumItem> mLstData) {
		if (mLstData != null && mLstData.size() > 0) {
			this.mLstData = mLstData;
			this.notifyDataSetChanged();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mLstData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mLstData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.activity_startpetition_item, null);
			holder = new Holder();
			holder.image = (ImageView) convertView.findViewById(R.id.iv_image);
			holder.shade = convertView.findViewById(R.id.v_shade);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		AlbumItem item = mLstData.get(position);
		if (item.getBitmap() != null) {
			holder.image.setImageBitmap(item.getBitmap());
		} else {
			holder.image
					.setImageResource(R.drawable.icon_startpetition_image_default);
		}
		if (!TextUtils.isEmpty(item.getFlag())) {
			holder.shade.setVisibility(View.VISIBLE);
		} else {
			holder.shade.setVisibility(View.GONE);
		}
		return convertView;
	}

	private class Holder {
		public ImageView image;
		public View shade;
	}

}
